﻿@using PagedList;
@using PagedList.Mvc;
@model IPagedList<Project_2._2.Models.Person>
@{
    ViewBag.Title = "Quản Lý Tài Khoản";
    Layout = "~/Views/Shared/_AdminLayoutPage.cshtml";
}

<script src="~/Script/Jquery_Table_Sort/jquery-latest.js"></script>
<script src="~/Script/Jquery_Table_Sort/jquery.tablesorter.js"></script>

<script type="text/javascript" >
    $(document).ready(function() { 
        $("table").tablesorter({ sortList: [[0, 0]], headers:{10:{sorter:false}} });
    });

</script>

<style>
    .search {
        width: 100%;
        height: 40px;
        padding:10px 0 10px 10px;
        float:left;
    }
</style>

<div class="grid_12">
	<div class="block-border">
	    <div class="block-header">Quản Lý Tài Khoản
		    @Html.ActionLink("Thêm Mới", "Create", "AdminPerson", null, new { @class = "button" })
        @if(ViewBag.SBy != "0" && ViewBag.SBy != null )
        { 
            @Html.ActionLink("Trở Lại Danh Sách", "Default", "AdminPerson", null, new { @class="button"})
        }
	    </div>
		<div class="block-content" style="overflow:scroll">

            <div class="search">
              
                @using (Html.BeginForm("Default", "AdminPerson", FormMethod.Post, new  { id = "Form" }))
                {
                    List<SelectListItem> record = new List<SelectListItem>();
                    int macdinh = 0;
                    if (ViewBag.record != null)
                    {
                        macdinh = int.Parse(ViewBag.record);
                    }
                    else
                    {
                        macdinh = 1;
                    }
                    for (int i = 1; i < 4; i++)
                    {
                        if (macdinh == i)
                        { record.Add(new SelectListItem { Text = i+" Dòng", Value = i.ToString(), Selected = true }); }
                        else
                        { record.Add(new SelectListItem { Text = i+" Dòng", Value = i.ToString() }); }
                    }
                    
                    <span>Hiển Thị </span> @Html.DropDownList("soDong", record, new { @class = "select", onchange = "SelectedIndexChanged()" })
                
                    <span style="padding:0 10px 0 50px"> Từ Khóa </span> @Html.TextBox("KeyWorld", null, new { @class ="Textbox", @placeholder="Nhập từ khóa ...", @Value = ViewBag.Key}) 
                    List<SelectListItem> SearchBy = new List<SelectListItem>();
                    SearchBy.Add(new SelectListItem { Text = " --  Tìm Theo  -- ", Value = "0"});
                    SearchBy.Add(new SelectListItem { Text = "Mã", Value = "ID" });
                    SearchBy.Add(new SelectListItem { Text = "Tên Đăng Nhập", Value = "UserName" });
                    SearchBy.Add(new SelectListItem { Text = "Họ Tên", Value = "Name" });
                    SearchBy.Add(new SelectListItem { Text = "Điện Thoại", Value = "Phone" });
                    SearchBy.Add(new SelectListItem { Text = "Email", Value = "Email" });
                    if (ViewBag.SBy != null)
                    {
                        foreach (var item in SearchBy)
                        {
                            if (item.Value == ViewBag.SBy)
                            { item.Selected = true; break; }
                        }
                    }
                    else
                    { SearchBy[0].Selected = true; }
                    <span> &nbsp;&nbsp;&nbsp;</span>@Html.DropDownList("SearchBy",SearchBy, new { @class = "select" });
                    
                    List<SelectListItem> kieuTK = new List<SelectListItem>();
                    kieuTK.Add(new SelectListItem { Text = "Tìm gần đúng", Value = "1" });
                    kieuTK.Add(new SelectListItem { Text = "Tìm chính xác", Value = "2" });
                    if(ViewBag.SType != null)
                    {
                        foreach (var item in kieuTK)
                        {
                            if(item.Value == ViewBag.SType)
                            {
                                item.Selected = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        kieuTK[0].Selected = true; 
                    }
                    <span>  &nbsp;&nbsp;&nbsp; </span>@Html.DropDownList("SearchType",kieuTK, new { @class = "select" });
                    <input type="submit" value="Tìm Kiếm"  />
                
               }

            </div>
            @if(Model != null && Model.Count > 0)
            { 
            <table class="tablesorter" cellpadding="0" cellspacing="0">
		        <thead>
			        <tr>
                        <th >Mã</th>
                        <th>Quyền</th>
                        <th>Tên Đăng Nhập</th>
                        <th>Họ và Tên</th>
                        <th>Ngày Sinh</th>
                        <th>Giới Tính</th>
                        <th>Điện Thoại</th>
                        <th>Email</th>
                        <th>Địa Chỉ</th>
                        <th>Trạng Thái</th>
                        <th></th>
			        </tr>
                </thead>
                <tbody >
                    
                        @for (int i = 0; i < Model.Count; i++)
{
    if (i % 2 != 0)
    {
        <tr style="background-color:#eaeaea">
            <td style="width:35px">@Model[i].PersonId</td>
            <td style="width:50px">
                @if (Model[i].RoleId == 1)
                {  <span>Quản Trị</span>  }
                else
                {   <span>Người Dùng</span> }
        </td>
        <td style="min-width:90px">@Model[i].TenDangNhap</td>
        <td style="width:80px">@Model[i].HoTen</td>
        <td style="width:80px">@String.Format("{0:d-MM-yyyy}", Model[i].NgaySinh)</td>
        <td style="width:65px">
            @if (Model[i].GioiTinh == "Nam")
            {  <span>Nam</span>  }
            else
            {   <span>Nữ</span> }
        </td>
        <td style="width:70px">@Model[i].DienThoai</td>
        <td style="width:90px">@Model[i].Email</td>
        <td> @Model[i].DiaChi</td>
        <td>
            @if (Model[i].isDelete == true)
            {  <span>Đang Xóa</span>  }
            else
            {   <span>Bình Thường</span> }
    </td>
    <td style="width:70px">
        <a class="tableActionButton edit" rel="tooltip-top" title="Cập Nhật" href="@Url.Action("Update", "AdminPerson", new { id = Model[i].PersonId })"></a>

        <a class="tableActionButton delete" rel="tooltip-top" title="Delete" href="../AdminPerson/Delete/@Model[i].PersonId" onclick="return DeleteConfirm()"></a>
    </td>
</tr>
    }
    else
    {
                            <tr>
                                <td style="width:35px">@Model[i].PersonId</td>
                                <td style="width:50px">@if (Model[i].RoleId == 1)
                                                       {  <span>Quản Trị</span>  } else{   <span>Người Dùng</span> }          </td>
                                <td style="min-width:90px">@Model[i].TenDangNhap</td>
                                <td style="width:80px">@Model[i].HoTen</td>
                                <td style="width:80px">@String.Format("{0:d-MM-yyyy}", Model[i].NgaySinh)</td>
                                <td style="width:65px">
                                    @if (Model[i].GioiTinh == "Nam")
                                    {  <span>Nam</span>  }
                                    else
                                    {   <span>Nữ</span> }  
                                </td>
                                <td style="width:70px">@Model[i].DienThoai</td>
                                <td style="width:90px">@Model[i].Email</td>
                                <td > @Model[i].DiaChi</td>
                                <td>@if (Model[i].isDelete == true)
                                    {  <span>Đang Xóa</span>  } else{   <span>Bình Thường</span> }  </td>
                                <td style="width:70px">
                                    <a class="tableActionButton edit" rel="tooltip-top" title="Cập Nhật" href="@Url.Action("Update", "AdminPerson", new { id = Model[i].PersonId })"></a>
							
                                    <a class="tableActionButton delete" rel="tooltip-top" title="Delete" href="../AdminPerson/Delete/@Model[i].PersonId" onclick="return DeleteConfirm()"></a>
                                </td>
                            </tr>
                            }
                        }
                    
                </tbody>
                
            </table>
            <table cellpadding="0" cellspacing="0" style="width:100%; border-top:none; margin-top:-3px ">
               <tr>
                   <td style="width:65px; text-align:right; font-weight:bold;padding-top:2px "> 
                       <span style="border: 1px solid #808080; border-right: none; padding: 7px 15px; margin-top: 10px; border-radius: 4px 0 0 4px; background-color: #428bca; color:#ffffff"> Trang</span></td>
                   <td >
                       @if (ViewBag.Key == null && ViewBag.SBy == null)
                       {
                           @Html.PagedListPager(Model, page => Url.Action("Default", new { page, rd = ViewBag.record }), new PagedListRenderOptions() { LinkToFirstPageFormat = "<<", LinkToPreviousPageFormat = " < ", LinkToNextPageFormat = " > ", LinkToLastPageFormat = ">>" })
                        }
                       else
                       {
                           @Html.PagedListPager(Model, page => Url.Action("Default", new { page, rd = ViewBag.record,key =ViewBag.Key, SBy = ViewBag.SBy, SType = ViewBag.SType }), new PagedListRenderOptions() { LinkToFirstPageFormat = "<<", LinkToPreviousPageFormat = " < ", LinkToNextPageFormat = " > ", LinkToLastPageFormat = ">>" })
                        }
                   </td>
               </tr>
            </table>
            }
            else
            {
                <span>Không có dữ liệu .</span>
            }
		</div>
    </div>
</div>
<script>

    function DeleteConfirm() {
        if (confirm("Tất cả dữ liệu liên quan điều sẽ bị xóa.\nBạn có muốn xóa không ?"))
            return true;
        else
            return false;
    }

    function SelectedIndexChanged() {
        $('#Form').submit();
    }
</script>

